﻿import QtQuick 2.4
import QtQuick.Controls 2.5

// 导入自定义包
import com.mycompany.customType 1.0


SendReceiveForm {

    receiveEdit {

    }

    sendBtn.onClicked: {
        if (sendEdit.text.length <= 0){
            receiveEdit.append("文本长度不能为0");
        }
        var newText = sendEdit.text;
        if(comboBoxTxCharset.currentText !== qsTr("HEX") && comboBoxLineBreakType.enabled && comboBoxLineBreakType.currentText === qsTr("\\r\\n"))
        {// 替换\n为\r\n
            newText = newText.replace(/\n/g, qsTr("\r\n"));
        }
        // qml socket
        if (btSocket.connected && sendEdit.text.length > 0) {
            btSocket.stringData = newText;//sendEdit.text
        }
        // c++ socket
        var charsetType = BluetoothCtrlSingleton.EnumCharset_GBK;
        switch(comboBoxTxCharset.currentText)
        {
        case qsTr("HEX"):
            charsetType = BluetoothCtrlSingleton.EnumCharset_HEX;
            break;
        case qsTr("GBK"):
            charsetType = BluetoothCtrlSingleton.EnumCharset_GBK;
            break;
        case qsTr("UTF8"):
            charsetType = BluetoothCtrlSingleton.EnumCharset_UTF8;
            break;
        case qsTr("UNICODE"):
            charsetType = BluetoothCtrlSingleton.EnumCharset_UNICODE;
            break;
        }
        //console.log("Tx chartset:" + charsetType)
        BluetoothCtrlSingleton.sendData(newText, charsetType);
    }

    comboBoxRxCharset.onCurrentTextChanged: {
        var charsetType = BluetoothCtrlSingleton.EnumCharset_GBK;
        switch(comboBoxRxCharset.currentText)
        {
        case qsTr("HEX"):
            charsetType = BluetoothCtrlSingleton.EnumCharset_HEX;
            break;
        case qsTr("GBK"):
            charsetType = BluetoothCtrlSingleton.EnumCharset_GBK;
            break;
        case qsTr("UTF8"):
            charsetType = BluetoothCtrlSingleton.EnumCharset_UTF8;
            break;
        case qsTr("UNICODE"):
            charsetType = BluetoothCtrlSingleton.EnumCharset_UNICODE;
            break;
        }
        //console.log("Rx chartset:" + charsetType)
        BluetoothCtrlSingleton.setReceiveCharsetType(charsetType);
    }
}











/*##^## Designer {
    D{i:0;autoSize:true;height:480;width:640}
}
 ##^##*/
